from fastapi import APIRouter, Depends
from utils.mysql import get_db
from utils.response import success, error
from app.model.dept_model import DepartmentModel

departmentApi= APIRouter(tags=['部门管理'], prefix="/user")

@departmentApi.get('/page', summary="部门查询")
def page( db=Depends(get_db)):
    data = DepartmentModel(db).get_page({}, 1, 10)
    return success("OK", data)

@departmentApi.get('/get', summary="部门详情")
def get(uid: int, db=Depends(get_db)):
    dep = DepartmentModel(db).get_by_id(1)
    return success("OK", dep)

@departmentApi.post('/add', summary="添加部门")
def add(db=Depends(get_db)):
    uid = DepartmentModel(db).add({"depname":"aasdfasf"})
    return success("OK")

@departmentApi.post('/edit', summary="编辑部门")
def edit(db=Depends(get_db)):
    r = DepartmentModel(db).edit({"id":2, "depname":"123123", "memo":"张三"})
    print(r)
    return success("OK")

@departmentApi.post('/del', summary="删除部门")
def delete(db=Depends(get_db)):
    r = DepartmentModel(db).delete(2)
    print(r)
    return success("OK")
